<template>
  <div class="select-bank-bg">
    <div class="select-bank-header">
      <el-button link class="back-btn" @click="goBack">
        <el-icon><ArrowLeft /></el-icon>
      </el-button>
      <span class="select-bank-title">选择银行</span>
    </div>
    <div class="select-bank-list">
      <div v-for="group in bankGroups" :key="group.letter">
        <div class="bank-group-title">{{ group.letter }}</div>
        <div v-for="bank in group.banks" :key="bank.name" class="bank-item" @click="selectBank(bank)">
          <img :src="bank.logo" class="bank-logo" />
          <span class="bank-name">{{ bank.name }}</span>
        </div>
      </div>
    </div>
    <div class="bank-index-bar">
      <div v-for="letter in indexList" :key="letter" class="index-letter">{{ letter }}</div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { ArrowLeft } from '@element-plus/icons-vue'
import logoImg from '../assets/logo.png'
const router = useRouter()
function goBack() {
  router.back()
}
function selectBank(bank) {
  router.replace({
    path: '/add-bank-card',
    query: {
      ...router.currentRoute.value.query,
      cardType: bank.name + ' 储蓄卡',
      cardLogo: bank.logo
    }
  })
}
const bankGroups = ref([
  {
    letter: 'A',
    banks: [
      { name: '中国建设银行', logo: logoImg },
      { name: '中国工商银行', logo: logoImg },
      { name: '中国银行', logo: logoImg },
      { name: '中国农业银行', logo: logoImg },
    ]
  },
  {
    letter: 'B',
    banks: [
      { name: '上海浦东发展银行', logo: logoImg },
      { name: '招商银行', logo: logoImg },
      { name: '中信银行', logo: logoImg },
    ]
  },
  {
    letter: 'C',
    banks: [
      { name: '安徽省农村信用社联合社', logo: logoImg },
      { name: '江苏省农村商业银行', logo: logoImg },
      { name: '浙江省农村信用社联合社', logo: logoImg },
    ]
  }
])
const indexList = ref(['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'])
</script>

<style scoped>
.select-bank-bg {
  background: #f5f7fa;
  min-height: 100vh;
  position: relative;
}
.select-bank-header {
  display: flex;
  align-items: center;
  padding: 18px 0 0 0;
  background: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid #f2f2f2;
}
.back-btn {
  font-size: 1.1em;
  color: #409EFF;
  padding: 0 0 0 8px;
  margin-right: 8px;
}
.select-bank-title {
  flex: 1;
  text-align: center;
  font-size: 1.1em;
  font-weight: bold;
  color: #222;
}
.select-bank-list {
  max-width: 480px;
  margin: 0 auto;
  padding: 8px 0 0 0;
}
.bank-group-title {
  background: #f5f7fa;
  color: #bbb;
  font-size: 1em;
  padding: 8px 16px 4px 16px;
  font-weight: bold;
}
.bank-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: #fff;
  border-bottom: 1px solid #f2f2f2;
  cursor: pointer;
  transition: background 0.2s;
}
.bank-item:last-child {
  border-bottom: none;
}
.bank-item:hover {
  background: #f0faff;
}
.bank-logo {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  margin-right: 14px;
  object-fit: cover;
  background: #f5f5f5;
}
.bank-name {
  font-size: 1.05em;
  color: #222;
}
.bank-index-bar {
  position: fixed;
  right: 8px;
  top: 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 20;
  user-select: none;
}
.index-letter {
  color: #bbb;
  font-size: 0.98em;
  padding: 2px 0;
  cursor: pointer;
}
</style> 